package com.steward.controller.card;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.steward.commons.Result;
import com.steward.dto.card.CardConsumeDTO;
import com.steward.dto.card.UserCardDTO;
import com.steward.server.card.CardActiveService;
import com.steward.server.card.CardService;

/**
 * 用户年卡查询
 * 
 * @author mastercheng
 * @since 2017-03-07 20:43:53
 */
@RestController
public class CustomerCardController {

	private static Logger logger = Logger.getLogger(CustomerCardController.class);

	@Resource
	private CardService cardService;
	@Resource
	private CardActiveService cardActiveService;

	/**
	 * 查询年卡信息
	 * 
	 * @param userId
	 * @return
	 */
	@GetMapping("/main/ver1/queryUserCard/{userId}")
	public @ResponseBody String UserYearCardController(@PathVariable("userId") String userId) {
		logger.info("UserYearCardController>>userId" + userId);
		Result<List<UserCardDTO>> result = cardService.queryUserCardList(userId);
		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
	}

	/**
	 * 查询用户年卡消费记录
	 * 
	 * @param cardId
	 * @return
	 */
	@GetMapping("/main/ver1/queryCardConsumeList/{cardId}")
	public @ResponseBody String queryCardConsumeList(@PathVariable("cardId") String cardId) {
		logger.info("queryCardConsumeList>>cardId" + cardId);
		Result<List<CardConsumeDTO>> result = cardService.queryCardConsumeList(cardId);
		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
	}

	/**
	 * 年卡激活
	 * 
	 * @param storeId
	 *            会员卡卡号
	 * @param userId
	 *            Mob_reg表，手机号
	 * @param activeId
	 *            激活码
	 * @return
	 */
	@GetMapping("/main/ver1/userCardActive/{cardNO}/{phone}/{activeId}")
	public @ResponseBody String UserCardActive(@PathVariable("cardNO") String cardNO,
			@PathVariable("phone") String phone, @PathVariable("activeId") String activeID) {
		Result<String> result = cardActiveService.activeCard(cardNO, activeID, phone);
		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
	}

}
